<%@page contentType="text/html;charset=utf-8" pageEncoding="UTF-8"%>
<%@taglib prefix="t" tagdir="/WEB-INF/tags"%>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<t:template>
	<jsp:attribute name="include">
		<c:if test="${showBuyButton }">
			<script type="text/javascript">
				function showModal() {
					$("#confirmModal").modal('show');
				}
			</script>
		</c:if>
	</jsp:attribute>
	<jsp:attribute name="pagetitle">
		<div style="width: 95%;">
			<c:out value="${merch.name }" />
			<div class="pull-right btn-group">
				<c:if test="${showBuyButton }">
					<a href="#" class="btn btn-info <c:if test="${currentUserMoney<merch.price }">disabled</c:if>" id="buy"
						onclick="showModal(); return false;">Megveszem</a>
				</c:if>
			</div>
		</div>
    </jsp:attribute>
	<jsp:body>
		<div style="float: left; max-width: 400px;">
		<form:form class="form-horizontal">
			<div class="control-group">
			    <label class="control-label" for="usernameText">Megnevezés:</label>
			    <div class="controls">
			      <div id="usernameText" class="formTextCenter">
			      	<c:out value="${merch.name }" />
			      </div>
			    </div>
			</div>
		
			<div class="control-group">
			    <label class="control-label" for="usernameText">Tulajdonos:</label>
			    <div class="controls">
			      <div id="usernameText" class="formTextCenter">
			      	<a
								href="<c:url value="/profile/"/><c:out value="${merch.username }"/>"><c:out
									value="${merch.username }" /></a>
			      </div>
			    </div>
			</div>
			
			<div class="control-group">
			    <label class="control-label" for="category">Kategória:</label>
			    <div class="controls">
			      <div id="category" class="formTextCenter">
			      	<c:out value="${merch.category.label }" />
			      </div>
			    </div>
			</div>
			
			<div class="control-group">
			    <label class="control-label" for="price">Ár:</label>
			    <div class="controls">
			      <div id="price" class="formTextCenter">
			      	<c:out value="${merch.price } Ft" />
			      </div>
			    </div>
			</div>
			
			<div class="control-group">
			    <label class="control-label" for="lastchange">Utolsó módosítás:</label>
			    <div class="controls">
			      <div id="lastchange" class="formTextCenter">
			      	<fmt:formatDate value="${merch.lastchange }"
								pattern="yyyy.MM.dd. HH:mm" type="BOTH" />
			      </div>
			    </div>
			</div>
			<div class="control-group">
			    <label class="control-label" for="description">Leírás:</label>
			    <div class="controls">
			      <div id="description" class="formTextCenter">
			      	<c:out value="${merch.description }"/>
			      </div>
			    </div>
			</div>			
		</form:form>
		</div>
		<c:if test="${picExists }">
			<a href="<c:url value="${filePath}"/>"><img alt="kep" src="<c:url value="${filePath}"/>" style="float: right; max-width: 250px; max-height: 380px;" class="img-polaroid"></a>
		</c:if>
		<c:if test="${showBuyButton }">
		<div class="modal hide fade" id="confirmModal">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal"
							aria-hidden="true">&times;</button>
				<h3>
					<span id="headTitle"><c:choose><c:when test="${currentUserMoney>merch.price }">Megerősítés</c:when><c:otherwise>Hiba</c:otherwise></c:choose>
					</span>
				</h3>
			</div>
			<div class="modal-body">
				<c:choose>
					<c:when test="${currentUserMoney>=merch.price }">Biztosan megveszed?</c:when>
					<c:otherwise>Nincs elég pénzed ennek a terméknek a megvételére...</c:otherwise>
				</c:choose>
			</div>
			<div class="modal-footer">
				<form action="<c:url value="/shop/sales/buy"/>">
					<input type="hidden" value="${merch.id }" name="merchId" />
					<div class="btn-group">
						<c:if test="${currentUserMoney>=merch.price }">
						<input type="submit" class="btn btn-primary" value="Megveszem" />
						</c:if>
						<a href="#" class="btn" data-dismiss="modal">Bezárás</a>
					</div>
				</form>
			</div>
		</div>
		</c:if>
    </jsp:body>
</t:template>